package com.krtech.wecard.framework.security;

import cn.dev33.satoken.strategy.SaStrategy;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;

public class InnerInterceptor extends HandlerInterceptorAdapter {


    // 在业务处理器处理请求之前被调用
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {



        // 获取处理method
        if (handler instanceof HandlerMethod == false) {
            return true;
        }
        Method method = ((HandlerMethod) handler).getMethod();

        // 进行验证
        SaStrategy.me.checkMethodAnnotation.accept(method);

        request.getMethod();
        Inner annotation = ((HandlerMethod) handler).getMethod().getAnnotation(Inner.class);
        if (annotation != null){
            if (!annotation.value()){
                return true;
            }
        }

        // 通过验证

        return true;
    }
}
